// Copyright (C) ZHENG Zhong <heavyzheng nospam-at gmail D0T com>
//
// $Id: adjusted_date.hpp 225 2008-09-12 17:43:02Z heavyzheng $
//

#ifndef ZZHENG_QUANT_DATES_ADJUSTED_DATE_HPP_20080613__
#define ZZHENG_QUANT_DATES_ADJUSTED_DATE_HPP_20080613__

#include <zzheng/quant/dates/config.hpp>
#include <zzheng/quant/dates/date.hpp>

namespace zzheng {
namespace quant {
namespace dates {

    class adjusted_date {

    public:

        //! Constructs an empty adjusted date.
        explicit adjusted_date(): adjusted_(), unadjusted_() {
            // Do nothing.
        }

        //! Constructs an adjusted date.
        //! \param d  the date which is used as the adjusted date and also the unadjusted one.
        explicit adjusted_date(const date& d): adjusted_(d), unadjusted_(d) {
            // Do nothing.
        }

        //! Constructs an adjusted date.
        //! \param adjusted    the adjusted date.
        //! \param unadjusted  the corresponding unadjusted date.
        explicit adjusted_date(const date& adjusted, const date& unadjusted)
        : adjusted_(adjusted), unadjusted_(unadjusted) {
            // Do nothing.
        }

        //! Returns the adjusted date.
        //! \return the adjusted date.
        const date& adjusted() const {
            return adjusted_;
        }

        //! Returns the corresponding unadjusted date.
        //! \return the corresponding unadjusted date.
        const date& unadjusted() const {
            return unadjusted_;
        }

        bool operator==(const adjusted_date& rhs) const {
            return (adjusted_ == rhs.adjusted_ && unadjusted_ == rhs.unadjusted_);
        }

        bool operator<(const adjusted_date& rhs) const {
            if (adjusted_ < rhs.adjusted_) {
                return true;
            } else if (adjusted_ == rhs.adjusted_) {
                return (unadjusted_ < rhs.unadjusted_);
            } else {
                return false;
            }
        }

        bool operator!=(const adjusted_date& rhs) const {
            return !operator==(rhs);
        }

        bool operator>(const adjusted_date& rhs) const {
            return (!operator==(rhs) && !operator<(rhs));
        }

        bool operator<=(const adjusted_date& rhs) const {
            return (operator==(rhs) || operator<(rhs));
        }

        bool operator>=(const adjusted_date& rhs) const {
            return !operator<(rhs);
        }

    private:

        date adjusted_;   //!< The adjusted date.
        date unadjusted_; //!< The corresponding unadjusted date.

    }; // class adjusted_date

} // namespace zzheng::quant::dates
} // namespace zzheng::quant
} // namespace zzheng

#endif // ZZHENG_QUANT_DATES_ADJUSTED_DATE_HPP_20080613__


